// pages/myBankCard/myBankCardAdd.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    seleted: "",
    name:"",
    bankNane:"",
    bankNo:"",
    bankNoTo:"",
    Iphone:""
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    //获取手机高度
    this.setData({
      navT: app.globalData.navTop,
      navLH: app.globalData.navLineHeight,
      navH: app.globalData.navHeight,
      modelmes: app.globalData.modelmes
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      token: wx.getStorageSync("token")
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //是否选中
  checkedTap: function () {
    var checked = this.data.checked;
    this.setData({
      "checked": !checked
    })
  },
  //提交
  save: function (e) {
    var userid = wx.getStorageSync("userId");
    var that = this;
    console.info(that.data.name);
    if(that.data.name == "") {
      wx.showToast({
        title: '姓名不能为空！',
        icon: "none"
      })
      return false
    }
    if (that.data.bankNane == "") {
      wx.showToast({
        title: '开户行不能为空！',
        icon: "none"
      })
      return false
    }
    if (that.data.bankNo == "") {
      wx.showToast({
        title: '银行卡号不能为空！',
        icon: "none"
      })
      return false
    }
    if (!(/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(that.data.bankNoTo))) {
      wx.showToast({
        title: '身份证号码有误',
        duration: 2000,
        icon: 'none'
      });
      return false;
    }
    if (that.data.Iphone == "") {
      wx.showToast({
        title: '手机号不能为空！',
        icon: "none"
      })
      return false
    }
    wx.request({
      url: app.globalData.url + "addNewBankCard",
      header: {
        "content-type": "application/x-www-form-urlencoded"
      },
      data: {
        userId: userid,
        cardNo: that.data.bankNo,
        bankName: that.data.bankNane,
        name: that.data.name,
        telephone: that.data.Iphone,
        token: that.data.token
      },
      method: "POST",
      success: function (res) {
        var data = res.data;
        if (data.result == 1){
          if (res.data.token != "" && res.data.token != undefined) {
            wx.setStorageSync("token", res.data.token)
          }
          wx.showToast({
            title: '添加成功！',
            icon: 'success',
            duration: 2000
          });
          wx.navigateBack({
            url: '/pages/myBankCard/myBankCard?userId=' + userid,
          })
        }
        if (res.data.result == 9) {
          wx.reLaunch({
            url: '/pages/zcuslist/index',
          })
          return false;
        }
        if (res.data.result == 0) {
          wx.showToast({
            title: res.data.errmsg,
            icon: "none"
          })
          return false;
        }
      }
    });
  },
  name: function (e) {
    this.setData({
      name: e.detail.value,
    })
  },
  bankNane: function (e) {
    this.setData({
      bankNane: e.detail.value,
    })
  },
  bankNo: function (e) {
    this.setData({
      bankNo: e.detail.value,
    })
  },
  bankNoTo: function (e) {
    this.setData({
      bankNoTo: e.detail.value,
    })
  },
  Iphone: function (e) {
    this.setData({
      Iphone: e.detail.value,
    })
  },
  agreement:function(){
    wx.navigateTo({
      url: '/pages/webView/webView?url=' + app.globalData.url + 'getWebPage&webId=userServiceProtocol'
      //url: '/pages/webView/webView?url=http://47.104.96.96/yixuanqi/getWebPage'
    })
  },
  navBack: function () {
    wx.navigateBack({

    })
  }
})